package openadmin.dao.exception;

import java.util.ResourceBundle;

import javax.swing.JFrame;
import javax.swing.JOptionPane;

import openadmin.util.configuration.TypeEnvironment;

public class Fail {

	ResourceBundle language;	
	TypeEnvironment environment;
	JFrame frame; 
	
	public Fail (ErrorDao pError, String pText, String pClassError, ResourceBundle pLanguage, TypeEnvironment pEnvironment) {    	    	
    	
    	environment = pEnvironment;
    	language = pLanguage;
    	
    	if (pError.equals(ErrorDao.PERSIST)&& pClassError.equals("javax.persistence.EntityExistsException")){    		
    		DisplayedError(pText + " " + language.getString("ERROR_PK"));    		
    	}
    	else if (pError.equals(ErrorDao.PERSIST)&& pClassError.equals("javax.persistence.PersistenceException")){    		
    		DisplayedError(pText + "\n" + language.getString("ERROR_UNIQUE"));    		
    	}  
    	else DisplayedError("Error no tipificat" + "\n " + pText + "\n " + pClassError);
    }
	
	 private void DisplayedError(String pTextError){
	    	
	    	if (environment.equals(TypeEnvironment.SWING))DisplayedSwing(pTextError);
	    }
	    
	 private void DisplayedSwing(String pTextError){
			
	    	JOptionPane.showMessageDialog(frame, pTextError, language.getString("ERROR"), JOptionPane.ERROR_MESSAGE);
	    	
			
	}
	 
}
